package com.imcode;

import java.io.FileReader;
import java.io.IOException;
import java.io.Reader;
import java.util.Properties;

public class DBUtil {

    private final static Properties prop;
    private final static String USERNAME = "username";
    private final static String PASSWORD = "password";

    static {
        prop = new Properties();
        Reader fr = null;
        try {
            fr = new FileReader("config/db.properties");
            prop.load(fr);
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (fr != null) {
                try {
                    fr.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }

    public static void getConnection(String username, String password) {
        // 判断输入的用户名和密码是否正确
        if (!prop.getProperty(USERNAME).equals(username)) {
            System.out.println("用户名错误");
        } else if (!prop.getProperty(PASSWORD).equals(password)) {
            System.out.println("密码错误");
        } else {
            System.out.println("登录成功");
        }
    }


    public static void main(String[] args) {
        DBUtil.getConnection("root", "123456");
    }
}
